package com.Liyunhan.design;

import java.awt.Color;
import java.util.ArrayList;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;

/**
 * @Description: 对得到的数据进行绘图
 * @Author: Liyunhan
 * @Date: 2021/12/19 17:20
 */
public class MyJfreechart {

    private ArrayList simuResults;
    private ArrayList calResults;

    public MyJfreechart(ArrayList simuResults, ArrayList calResults) {
        this.simuResults = simuResults;
        this.calResults = calResults;
    }

    //    public static void main(String[] args) {
//        CategoryDataset mDataset = this.GetDataset();
//        JFreeChart mChart = ChartFactory.createLineChart(
//                "折线图",//图名字
//                "year",//横坐标
//                "数量",//纵坐标
//                mDataset,//数据集
//                PlotOrientation.VERTICAL,
//                true, // 显示图例
//                true, // 采用标准生成器
//                false);// 是否生成超链接
//
//        CategoryPlot mPlot = (CategoryPlot)mChart.getPlot();
//        mPlot.setBackgroundPaint(Color.LIGHT_GRAY);
//        mPlot.setRangeGridlinePaint(Color.BLUE);//背景底部横虚线
//        mPlot.setOutlinePaint(Color.RED);//边界线
//
//        ChartFrame mChartFrame = new ChartFrame("折线图", mChart);
//        mChartFrame.pack();
//        mChartFrame.setVisible(true);
//
//    }
    public JFreeChart getChartObj() {
        CategoryDataset mDataset = this.GetDataset();
        JFreeChart mChart = ChartFactory.createLineChart(
                "Line chart",//图名字
                "exp",//横坐标
                "probability",//纵坐标
                mDataset,//数据集
                PlotOrientation.VERTICAL,
                true, // 显示图例
                true, // 采用标准生成器
                false);// 是否生成超链接
        return mChart;
    }

    /**
     * 添加数据
     * @return
     */
    public CategoryDataset GetDataset() {
        DefaultCategoryDataset mDataset = new DefaultCategoryDataset();
        for (int i = 0; i < simuResults.size(); i++) {
            mDataset.addValue((Double) simuResults.get(i), "SimuData", i+" ");
        }
        for (int i = 0; i < calResults.size(); i++) {
            mDataset.addValue((Double) calResults.get(i), "FormulaData", i+" ");
        }
//        mDataset.addValue(1, "First", "2013");
//        mDataset.addValue(3, "First", "2014");
//        mDataset.addValue(2, "First", "2015");
//        mDataset.addValue(6, "First", "2016");
//        mDataset.addValue(5, "First", "2017");
//        mDataset.addValue(12, "First", "2018");
//        mDataset.addValue(14, "Second", "2013");
//        mDataset.addValue(13, "Second", "2014");
//        mDataset.addValue(12, "Second", "2015");
//        mDataset.addValue(9, "Second", "2016");
//        mDataset.addValue(5, "Second", "2017");
//        mDataset.addValue(7, "Second", "2018");
        return mDataset;
    }
}
